//
//  CPTabBarItem.m
//  CPTabBarController
//
//  Created by Morplcp on 2018/11/6.
//  Copyright © 2018 morplcp. All rights reserved.
//

#import "CPTabBarItem.h"
#import "CPTabBar.h"

@interface CPTabBarItem ()

@end

@implementation CPTabBarItem

- (void)dealloc
{
    NSLog(@"释放了就很棒");
}

- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.badgeType = CPBadgeTypeNumber;
        self.badgeTitleColor = [UIColor whiteColor];
    }
    return self;
}

- (void)setBadgeType:(CPBadgeType)badgeType
{
    _badgeType = badgeType;
    self.cp_tabBarButton.badgeType = badgeType;
}

- (void)setBadgeNumber:(NSInteger)badgeNumber
{
    _badgeNumber = badgeNumber;
    if (self.badgeType == CPBadgeTypeNumber)
    {
        if (badgeNumber <= 0)
        {
            self.cp_tabBarButton.badgeView.hidden = YES;
            [self.cp_tabBarButton.badgeView setTitle:[NSString stringWithFormat:@"%ld", badgeNumber] forState:UIControlStateNormal];
        }
        else
        {
            self.cp_tabBarButton.badgeView.hidden = NO;
            [self.cp_tabBarButton.badgeView setTitle:[NSString stringWithFormat:@"%ld", badgeNumber] forState:UIControlStateNormal];
        }
    }
}

- (void)setShowBadgeDot:(BOOL)showBadgeDot
{
    _showBadgeDot = showBadgeDot;
    if (self.badgeType == CPBadgeTypeDot)
    {
        self.cp_tabBarButton.badgeView.hidden = !showBadgeDot;
    }
}

- (void)setBadgeIcon:(NSString *)badgeIcon
{
    _badgeIcon = badgeIcon;
    if (self.badgeType == CPBadgeTypeDot)
    {
        [self.cp_tabBarButton.badgeView setBackgroundImage:[[UIImage imageNamed:badgeIcon] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    }
}

- (void)setBadgeColor:(UIColor *)badgeColor
{
    [super setBadgeColor:badgeColor];
    self.cp_tabBarButton.badgeView.backgroundColor = badgeColor;
}

- (void)setBadgeTitleColor:(UIColor *)badgeTitleColor
{
    _badgeTitleColor = badgeTitleColor;
    [self.cp_tabBarButton.badgeView setTitleColor:badgeTitleColor forState:UIControlStateNormal];
}

@end
